package com.xnyzc.lhy.mis.service.impl.worksheet;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xnyzc.lhy.common.component.redis.RedisCommon;
import com.xnyzc.lhy.common.constant.RedisPrefixConstant;
import com.xnyzc.lhy.common.exception.WorksheetException;
import com.xnyzc.lhy.common.penum.worksheet.WorksheetErrorCode;
import com.xnyzc.lhy.common.util.CheckUtil;
import com.xnyzc.lhy.mis.entity.order.OaCOrderPersonal;
import com.xnyzc.lhy.mis.mapper.order.OaCOrderPersonalMapper;
import com.xnyzc.lhy.mis.service.worksheet.IOrderPersonalService;
import com.xnyzc.lhy.resource.entity.worksheet.param.WorksheetgetOrderPersonalListParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 订单接口实现类
 *
 * @author haoyfa
 */
@Service
public class OrderPersonalServiceImpl extends ServiceImpl<OaCOrderPersonalMapper, OaCOrderPersonal> implements IOrderPersonalService {
    /**
     * redis私有方法
     */
    @Autowired
    private RedisCommon redisCommon;

    /**
     * 自费叫车Mapper
     */
    @Autowired
    private OaCOrderPersonalMapper oaCOrderPersonalMapper;

    /**
     * 查看订单详情
     *
     * @param orderNo
     * @return
     */
    @Override
    public OaCOrderPersonal getOrderDetail(String orderNo) {
        OaCOrderPersonal oaCOrderPersonal = null;

        QueryWrapper<OaCOrderPersonal> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(OaCOrderPersonal.ORDER_NO, orderNo);
        oaCOrderPersonal = oaCOrderPersonalMapper.selectOne(queryWrapper);

        if (CheckUtil.objIsEmpty(oaCOrderPersonal)) {
            throw WorksheetException.create(WorksheetErrorCode.orderPersonalSelectFail);
        }
        return oaCOrderPersonal;
    }

    /**
     * 根据手机号获取订单详情列表
     *
     * @param param 乘客电话号
     * @return
     */
    @Override
    public List<OaCOrderPersonal> getOrderDetailList(WorksheetgetOrderPersonalListParam param) {
        List<OaCOrderPersonal> oaCOrderPersonalList = oaCOrderPersonalMapper.selectListLimit(param);

        return oaCOrderPersonalList;
    }

    /**
     * 根据手机号获取订单详情列表总数
     *
     * @param param 用户ID
     * @return
     */
    @Override
    public Integer selectListLimitTotal(WorksheetgetOrderPersonalListParam param) {
        return oaCOrderPersonalMapper.selectListLimitTotal(param);
    }

    /**
     * 根据司机手机号获取订单详情列表
     *
     * @param param 乘客电话号
     * @return
     */
    @Override
    public List<OaCOrderPersonal> getDriverOrderDetailList(WorksheetgetOrderPersonalListParam param) {
        //if (CheckUtil.objIsNotEmpty(param.getIndex()) || param.getIndex() < 0) {
        //    param.setIndex(0);
        //} else {
        //    param.setIndex(param.getIndex() - 1);
        //}
        List<OaCOrderPersonal> oaCOrderPersonalList = oaCOrderPersonalMapper.selectDriverListLimit(param);

        return oaCOrderPersonalList;
    }

    /**
     * 根据司机手机号获取订单详情列表总数
     *
     * @param param 手机号
     * @return
     */
    @Override
    public Integer selectDriverListLimitTotal(WorksheetgetOrderPersonalListParam param) {
        return oaCOrderPersonalMapper.selectDriverListLimitTotal(param);
    }
}
